#!<%= dea_ruby_path || '/usr/bin/env ruby'%>
# Copyright (c) 2009-2011 VMware, Inc.
require 'optparse'
require 'fileutils'
require 'socket'

port = nil
parser = OptionParser.new do |opts|
  opts.on('-p', '--port PORT', Integer, 'Port to bind to') do |p|
    port = p
  end
end
parser.parse(ARGV)

fail 'Must supply port' unless port

stop_contents =<<-EOT
#!/bin/sh
echo Killing pid #{Process.pid}
kill -9 #{Process.pid}
EOT


stop_path = File.expand_path('../stop', __FILE__)
File.open(stop_path, 'w+') do |f|
  f.write(stop_contents)
end
FileUtils.chmod(0755, stop_path)

server = TCPServer.new('127.0.0.1', port)
while true do
  client = server.accept()
  client.close()
end
